import Vue from 'vue'
import VueRouter from 'vue-router'
import homeView from "../views/homeView.vue"

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect:"/home"
  },
  {
    path: '/home',
    name:"home",
    component:homeView,
    beforeEnter:(to,from,next)=>{
      let token = window.localStorage.getItem("token");
      if(!token){
        next("/login");
        return
      }else{
        next();
    }
  }
  }, 
  {
    path:'/video',
    name:'video',
    component: () => import('../views/videoView.vue'),
    beforeEnter:(to,from,next)=>{
      let token = window.localStorage.getItem("token");
      if(!token){
        next("/login");
        return
      }else{
        next();
      }
}
  },
  {
    path:'/talk',
    name:'talk',
    component: () => import('../views/talkView.vue')
  },
  {
    path:'/person',
    name:'person',
    component: () => import('../views/personView.vue'),
   
  },
  {
    path:'/ceshi',
    name:'ceshi',
    component: () => import('../views/ceshiView.vue')
  },
  {
    path:'/search',
    name:'search',
    component: () => import('../views/searchView.vue')
  },
  {
    path:'/login',
    name:'login',
    component: () => import('../views/loginView.vue')
  },
  {
    path:'/show',
    name:'show',
    component: () => import('../views/showView.vue')
  },
  {
    path:'/billion',
    name:'billion',
    component: () => import('../views/billionView.vue')
  },
  {
    path:'/myord',
    name:'myord',
    component: () => import('../views/myordView.vue')
  },
  {
    path:'/numlog',
    name:'numlog',
    component: () => import('../views/numlogView.vue')
  },
  {
    path:'/givemoney',
    name:'givemoney',
    component: () => import('../views/givemoneyView.vue')
  },
  {
    path:'/pinglun',
    name:'pinglun',
    component: () => import('../views/pinglunView.vue')
  },
  {
    path:'/welf',
    name:'welf',
    component: () => import('../views/welfView.vue')
  },
  {
    path:'/likes',
    name:'likes',
    component: () => import('../views/likesView.vue')
  },
  {
    path:'/newsele',
    name:'newsele',
    component: () => import('../views/newseleView.vue')
  },
  {
    path:'/searshow',
    name:'searshow',
    component: () => import('../views/searshowView.vue')
  },
  {
    path:'/saywhat',
    name:'saywhat',
    component: () => import('../views/saywhatView.vue')
  }
  
]

// 注意:解决路由跳转问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location){
  return originalPush.call(this,location).catch(err=>err);
}





const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
  scrollBehavior () {
      return { x: 0, y: 0 }
  }
})





// 配置全局路由守卫
// 用户必须登录才进入  必须登录才可以进入
// router.beforeEach((to,from,next)=>{
//   let token = window.localStorage.getItem("token");
//   // 登录界面判断
//   if(to.path == "/login"){
//       next();
//       return;
//   }else{ //判断是否登录
//     if(!token){
//       next("/login");//进入登录页面
//       return;
//     }else{
//       next();//执行下一个路由
//     }
//   }
// })



export default router
